package com.sskj.fca;

import android.support.multidex.MultiDexApplication;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.service.ClassLoaderService;
import com.alibaba.android.arouter.launcher.ARouter;
import com.sskj.common.router.service.CommonService;
import com.sskj.fca.ui.activity.MainActivity;
import com.sskj.lib.router.service.LibService;
import com.tencent.bugly.crashreport.CrashReport;
import com.zxy.recovery.core.Recovery;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * 作者 :吕志豪
 * 简书：https://www.jianshu.com/u/6e525b929aac
 * github：https://github.com/lvzhihao100
 * 描述：
 * 创建时间：2018-10-18 08:52
 */
public class BaseApplication extends MultiDexApplication {
    @Autowired
    CommonService commonService;
    @Autowired
    LibService libService;

    @Override
    public void onCreate() {
        super.onCreate();
        closeAndroidPDialog();
        ARouter.openLog();
        ARouter.openDebug();
        ARouter.init(this);
        ARouter.getInstance().inject(this);
//        Recovery.getInstance()
//                .debug(true)
//                .recoverInBackground(false)
//                .recoverStack(true)
//                .mainPage(MainActivity.class)
//                .recoverEnabled(true)
//                .callback(null)
//                .silent(false, Recovery.SilentMode.RECOVER_ACTIVITY_STACK)
//                .init(this);
        CrashReport.initCrashReport(this, "7fa878c5c3", true);

    }

    private void closeAndroidPDialog() {
        try {
            Class aClass = Class.forName("android.content.pm.PackageParser$Package");
            Constructor declaredConstructor = aClass.getDeclaredConstructor(String.class);
            declaredConstructor.setAccessible(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            Class cls = Class.forName("android.app.ActivityThread");
            Method declaredMethod = cls.getDeclaredMethod("currentActivityThread");
            declaredMethod.setAccessible(true);
            Object activityThread = declaredMethod.invoke(null);
            Field mHiddenApiWarningShown = cls.getDeclaredField("mHiddenApiWarningShown");
            mHiddenApiWarningShown.setAccessible(true);
            mHiddenApiWarningShown.setBoolean(activityThread, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
